/*
 * Copyright (c) Tan Menglong <TanMenglong@gmail.com> <+86-15972108715>
 * All rights reserved.
 *
 * This file is part of the RabbitOS.  The RabbitOS is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the Rabbit OS team.
 * 
 * The RabbitOS is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
 * received a copy of the GPL along with the RabbitOS; see the file COPYING. If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 *
 */
/*
 * Definations of GDT.
 * 03-Mar-08
 */

#ifndef _RABBIT_DT_H
#define _RABBIT_DT_H

#include "isr.h"
#include <sys/types.h>

struct gdt_entry_struct {
	u16int limit_low;
	u16int base_low;
	u8int base_middle;
	u8int access;
	u8int granularity;
	u8int base_high;
} __attribute__ ((packed));

struct gdt_ptr_struct {
	u16int limit;
	u32int base;
} __attribute__ ((packed));

struct idt_entry_struct {
	// The lower 16 bits of the address to jump to when this interrupt fires.
	u16int base_lo;
	// Kernel segment selector.
	u16int sel;
	// This must always be zero.
	u8int always0;
	// More flags. See documentation.
	u8int flags;
	// The upper 16 bits of the address to jump to.
	u16int base_hi;
} __attribute__ ((packed));

struct idt_ptr_struct {
	u16int limit;
	// The address of the first element in our idt_entry_t array.
	u32int base;
} __attribute__ ((packed));

typedef struct gdt_entry_struct gdt_entry_t;
typedef struct gdt_ptr_struct gdt_ptr_t;

typedef struct idt_entry_struct idt_entry_t;
typedef struct idt_ptr_struct idt_ptr_t;

// Extern the ISR handler array so we can nullify them on startup.
extern isr_t interrupt_handlers[];

extern void init_dt(void);
extern void init_gdt(void);
extern void flush_gdt(u32int);
extern void set_gdt_gate(s32int, u32int, u32int, u8int, u8int);
extern void init_idt(void);
extern void gdt_flush(u32int);

// These extern directives let us access the addresses of our ASM ISR handlers.
extern void isr0();
extern void isr1();
extern void isr2();
extern void isr3();
extern void isr4();
extern void isr5();
extern void isr6();
extern void isr7();
extern void isr8();
extern void isr9();
extern void isr10();
extern void isr11();
extern void isr12();
extern void isr13();
extern void isr14();
extern void isr15();
extern void isr16();
extern void isr17();
extern void isr18();
extern void isr19();
extern void isr20();
extern void isr21();
extern void isr22();
extern void isr23();
extern void isr24();
extern void isr25();
extern void isr26();
extern void isr27();
extern void isr28();
extern void isr29();
extern void isr30();
extern void isr31();

// don't forget to handle irq - liuw
extern void irq0();
extern void irq1();
extern void irq2();
extern void irq3();
extern void irq4();
extern void irq5();
extern void irq6();
extern void irq7();
extern void irq8();
extern void irq9();
extern void irq10();
extern void irq11();
extern void irq12();
extern void irq13();
extern void irq14();
extern void irq15();
#endif							//_RABBIT_DT_H
